﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FileOps;
using System.Threading;
using System.Windows;
using BAL.EstRec.Common;

namespace BAL.EstRec.SyncCierre
{
    public class ThreadSyncCierre
    {
        public static Thread t = null;
        public static FolderSync fs;


        public ThreadSyncCierre()
        {
        }


        public static bool CheckIsAlive()
        {

            if (ThreadSyncCierre.t != null)
            {
                return ThreadSyncCierre.t.IsAlive;

            }
            return false;

        }/////////

        public static void start(IUIRefresher uiRefresher)
        {
            if (!ThreadSyncCierre.CheckIsAlive())
            {
                ThreadSyncCierre.t = new Thread(() => ThreadSyncCierre.syncCierre(uiRefresher));
                ThreadSyncCierre.t.IsBackground = true;
                ThreadSyncCierre.t.Start();
            }
        }

        public static void syncCierre(IUIRefresher uiRefresher)
        {
            try
            {
                SincronizarArchivosFDV sfg= new SincronizarArchivosFDV();
                if (sfg.atLeastOneUpdated)
                {
                    uiRefresher.invokeRefreshUI();
                }
                
            }
            catch (Exception ex)
            {
                ;
            }
        }

    }
}
